﻿using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace YArchitech.Public.Encrypt
{
	public static class HYStringEncryptUtility
	{
		public static string Decrypt(string str)
		{
			TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
			byte[] array = new byte[str.Length / 2];
			for (int i = 0; i < str.Length / 2; i++)
			{
				array[i] = (byte)Convert.ToInt32(str.Substring(i * 2, 2), 16);
			}
			tripleDESCryptoServiceProvider.Key = Convert.FromBase64String("uwniTq6wza7nU4/cCVxTScpjhlv1Tl5s");
			tripleDESCryptoServiceProvider.IV = Convert.FromBase64String("ld6Et92CmbQ=");
			MemoryStream memoryStream = new MemoryStream();
			CryptoStream cryptoStream = new CryptoStream(memoryStream, tripleDESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
			cryptoStream.Write(array, 0, array.Length);
			cryptoStream.FlushFinalBlock();
			new StringBuilder();
			return Encoding.Unicode.GetString(memoryStream.ToArray());
		}

		public static string Encrypt(string str)
		{
			TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
			byte[] bytes = Encoding.Unicode.GetBytes(str);
			tripleDESCryptoServiceProvider.Key = Convert.FromBase64String("uwniTq6wza7nU4/cCVxTScpjhlv1Tl5s");
			tripleDESCryptoServiceProvider.IV = Convert.FromBase64String("ld6Et92CmbQ=");
			MemoryStream memoryStream = new MemoryStream();
			CryptoStream cryptoStream = new CryptoStream(memoryStream, tripleDESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);
			cryptoStream.Write(bytes, 0, bytes.Length);
			cryptoStream.FlushFinalBlock();
			StringBuilder stringBuilder = new StringBuilder();
			foreach (byte b in memoryStream.ToArray())
			{
				stringBuilder.AppendFormat("{0:X2}", b);
			}
			return stringBuilder.ToString();
		}
	}
}
